package qu.sol2bpel.protocol;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import org.stringtemplate.v4.misc.MultiMap;

public class Protocol {

	private String protocol_name;
	private String client;
	private ArrayList<String> cloud_parties;
	private ArrayList<String> inputs;
	
	private ArrayList<String> outputs;
	
	private MultiMap<String,String> parties_functions;
	private MultiMap<String,String> parties_denys;
	
	private ArrayList<Setup_step> setup_steps;
	
	
	public Protocol()
	{
		setCloud_parties(new ArrayList<String>());
		setInputs(new ArrayList<String>());

		setOutputs(new ArrayList<String>());

		setParties_functions(new MultiMap<String, String>());
		setParties_denys(new MultiMap<String, String>());
		
		setSetup_steps(new ArrayList<Setup_step>());
	}
	
	public Protocol(Protocol p)
	{
		setProtocol_name(p.protocol_name);
		setClient(p.client);
		setCloud_parties(new ArrayList<String>(p.getCloud_parties()));
		setInputs(new ArrayList<String>(p.getInputs()));

		setOutputs(new ArrayList<String>(p.getOutputs()));

		setParties_functions(p.getParties_functions());
		setParties_denys(p.getParties_denys());
		setSetup_steps(p.getSetup_steps());
	}
	
	public String getProtocol_name() {
		return protocol_name;
	}

	public void setProtocol_name(String protocol_name) {
		this.protocol_name = protocol_name;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	
	public String getClient() {
		return client;
	}

	public void setClient(String client) {
		this.client = client;
	}

	
	public ArrayList<String> getInputs() {
		return inputs;
	}

	public void setInputs(ArrayList<String> inputs) {
		this.inputs = inputs;
	}

	public ArrayList<String> getOutputs() {
		return outputs;
	}

	public void setOutputs(ArrayList<String> outputs) {
		this.outputs = outputs;
	}

	public MultiMap<String,String> getParties_functions() {
		return parties_functions;
	}

	public void setParties_functions(MultiMap<String,String> parties_functions) {
		this.parties_functions = parties_functions;
	}

	public ArrayList<String> getCloud_parties() {
		return cloud_parties;
	}

	public void setCloud_parties(ArrayList<String> cloud_parties) {
		this.cloud_parties = cloud_parties;
	}
	
	public void addProtocolSetup_Step(String party, String op, ArrayList<String> inputs, ArrayList<String> outputs )
	{
		if(!setup_steps.contains(new Setup_step(party, op, inputs, outputs)))
		setup_steps.add(new Setup_step(party, op, inputs, outputs));
	}
	
	public void printProtocolMembers()
	{
		System.out.print("Protocol Name : "+ protocol_name);
		System.out.println();
		System.out.print("Client ID : "+ client);
		System.out.println();
		System.out.print("Set of parties : ");
		for(String s : getCloud_parties())
			System.out.print(s + ";  ");
		System.out.println();
		System.out.print("Set of inputs :  ");
		for(String i : getInputs())
			System.out.print(i + ";  ");
		System.out.println();
		System.out.print("Set of outputs :  ");
		for(String o : getOutputs())
			System.out.print(o + ";  ");
		System.out.println();
		System.out.print("Set of functions :  ");
		Iterator I = getParties_functions().keySet().iterator();
		while (I.hasNext())
		{
			String key=(String)I.next();
			Collection<String> party_functions = (Collection<String>)(parties_functions.get((String)key));
			System.out.print(key + ":  ");
			for(String f : party_functions)
				System.out.print(f + ";");
			System.out.println();
		}
		
		System.out.println("Deny rules : ");
		Iterator I2 = getParties_denys().keySet().iterator();
		while (I2.hasNext())
		{
			String key=(String)I2.next();
			Collection<String> party_denys = (Collection<String>)(parties_denys.get((String)key));
			System.out.print(key + ":  ");
			for(String d : party_denys)
				System.out.print(d + ";");
			System.out.println();
		}
		
		System.out.println("Protocol Steps : ");
		for(int j=0 ; j< this.getSetup_steps().size(); j++)
		{
			this.getSetup_steps().get(j).print();
		}
	}

	public MultiMap<String,String> getParties_denys() {
		return parties_denys;
	}

	public void setParties_denys(MultiMap<String,String> parties_denys) {
		this.parties_denys = parties_denys;
	}

	public ArrayList<Setup_step> getSetup_steps() {
		return setup_steps;
	}

	public void setSetup_steps(ArrayList<Setup_step> setup_steps) {
		this.setup_steps = setup_steps;
	}


}
